using SqlSugar;

namespace HtERP.Data
{
    [SugarTable("BackupSchedules")]
    public class BackupSchedule
    {
        [SugarColumn(IsPrimaryKey = true, IsIdentity = false)]
        public Guid Id { get; set; } = Guid.NewGuid();
        
        [SugarColumn(IsNullable = false)]
        public bool Enabled { get; set; } = true;
        
        [SugarColumn(IsNullable = false, ColumnDataType = "NVARCHAR(100)")]
        public string Name { get; set; } = string.Empty;
        
        [SugarColumn(IsIgnore = true)]
        public DbConnectionConfig DbConfig { get; set; } = new DbConnectionConfig();
        
        [SugarColumn(IsNullable = false, ColumnDataType = "NVARCHAR(255)")]
        public string BackupDirectory { get; set; } = string.Empty;
        
        [SugarColumn(IsNullable = false)]
        public int BackupIntervalMinutes { get; set; } = 60;
        
        [SugarColumn(IsIgnore = true)]
        public List<string> ScheduledBackupTimes { get; set; } = new List<string>();
        
        [SugarColumn(IsNullable = false)]
        public int AutoDeleteOlderThanDays { get; set; } = 30;
        
        [SugarColumn(IsNullable = false)]
        public int DiskSpaceThresholdMB { get; set; } = 1024;
        
        [SugarColumn(IsNullable = true, ColumnDataType = "NVARCHAR(255)")]
        public string CustomBackupFileName { get; set; } = string.Empty;
        
        [SugarColumn(IsNullable = false)]
        public bool UploadToServer { get; set; } = false;
        
        [SugarColumn(IsNullable = true, ColumnDataType = "NVARCHAR(255)")]
        public string ServerUrl { get; set; } = "https://localhost:5001/api";
        
        [SugarColumn(IsNullable = true, ColumnDataType = "NVARCHAR(50)")]
        public string ServerUsername { get; set; } = string.Empty;
        
        [SugarColumn(IsNullable = true, ColumnDataType = "NVARCHAR(100)")]
        public string ServerPassword { get; set; } = string.Empty;
        
        [SugarColumn(IsNullable = false)]
        public bool Compress { get; set; } = false;
        
        [SugarColumn(IsNullable = false)]
        public long LargeFileThreshold { get; set; } = 10 * 1024 * 1024;
        
        [SugarColumn(IsNullable = false)]
        public long ChunkSize { get; set; } = 5 * 1024 * 1024;
        
        [SugarColumn(IsNullable = false)]
        public int UploadTimeout { get; set; } = 60000;
        
        [SugarColumn(IsNullable = false)]
        public int MaxRetries { get; set; } = 3;
        
        [SugarColumn(IsNullable = false)]
        public int RetryInterval { get; set; } = 1000;
        
        [SugarColumn(IsNullable = false, ColumnDataType = "TEXT")]
        public string DbConfigJson
        {
            get { return Newtonsoft.Json.JsonConvert.SerializeObject(DbConfig); }
            set { DbConfig = Newtonsoft.Json.JsonConvert.DeserializeObject<DbConnectionConfig>(value); }
        }
        
        [SugarColumn(IsNullable = false, ColumnDataType = "TEXT")]
        public string ScheduledBackupTimesJson
        {
            get { return Newtonsoft.Json.JsonConvert.SerializeObject(ScheduledBackupTimes); }
            set { ScheduledBackupTimes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(value); }
        }
        
        [SugarColumn(IsNullable = false)]
        public DateTime CreatedAt { get; set; } = DateTime.Now;
        
        [SugarColumn(IsNullable = false)]
        public DateTime UpdatedAt { get; set; } = DateTime.Now;
    }
}